<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
<head>
<%@ include file="/commons/commonList.jsp"%>
<link href="${ctx}/styles/begins.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="${ctx}/scripts/common/prototype.js"></script>
<script type="text/javascript" src="${ctx}/scripts/ajaxException.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script type="text/javascript" defer>
	var currentId = null;
	var currentRow = null;

	var currentMethod = null;//当前点击的那个菜单,是修改还是调整
	function init(){
		resize();
	}
	function resize(){
		parent.window.document.all('meterDataFrame').style.height=document.body.scrollHeight;
	}
	//表格单击事件处理,当选中一条记录时,要求将其他行的颜色去掉
	function tableOnclickHandle(thiz){
		var tableObj = document.getElementById("ec_table");
		for(var i = 0; i < tableObj.rows.length; i++){
			tableObj.rows[i].className = "grid";
		}
		thiz.className='gridSelectOn';
	}
/**************菜单情况处理*********************/
	//修改菜单处理,当用户选择修改菜单时,要修文本输入框获取焦点,可以让用户输入
	function openEdit(){
		//先验证是否可以修改或者调整,然后设置文本框可以编辑
		var url = "${ctx}/charge_meterDataRegisterAction.do?method=validateEditable";
		var params = "chargeDataId=" + currentId;
		sendAjaxRequest(url,params,function(result){
			ajaxSubmitException(result.responseText);
			setInputStatus(); //设置文本框可以编辑
		});
	}
	//调整作废
	function openAdjust(){
		//先验证是否可以修改或者调整,然后设置文本框可以编辑
		var url = "${ctx}/charge_meterDataRegisterAction.do?method=validateAdjustable";
		var params = "chargeDataId=" + currentId;
		sendAjaxRequest(url,params,function(result){
			ajaxSubmitException(result.responseText);
			setInputStatus(); //设置文本框可以编辑
		});
	}

	/**
	 * 设置文本框可以编辑
	 */
	function setInputStatus(){
		var objs = currentRow.getElementsByTagName("input");
		if(objs == null || objs.length != 1) return;

		inputObj = objs[0];
		if(inputObj.className == 'inputNoStyle') inputObj.className='inputOver';
		currentInputValue=inputObj.value
		inputObj.focus();
		inputObj.readOnly = false;
	}
/******************文本框处理**************************/
	//文本框失去焦点时提交方法  table 单元格内容的改变  需在请求完成后条用
	var currentInputValue = null;
	function inputSubmit (thiz){
		if( currentInputValue == thiz.value) {//没有作任何修改
			thiz.readOnly = true;
			return;
		}
		if(thiz.value == "" || thiz.value == null) {
			thiz.value = currentInputValue;
			return;
		}

		if(!validation(thiz.value)){
			thiz.value = currentInputValue;
			Alert("${key.charge_meterDataList_ErrorReading}");
			return;
		}
		if(currentId == null) return;

		var url = "${ctx}/charge_meterDataRegisterAction.do?method=" + currentMethod;
		var param = "chargeDataId=" + currentId + "&thisReading=" + thiz.value;
		new Ajax.Request(url,{method: 'post',parameters: param,onComplete:function(result){
			var obj = result.responseText
			if(obj.indexOf("<script")>-1){ //如果出现异常 则设为原来的值
				thiz.value = currentInputValue;
			}
			ajaxSubmitException(result.responseText);
			parent.reloadFrame();
		}});
	}
	//验证输入的数字是否合法
	function validation(editValue){
		if(editValue == null) return ;
		var reg = /^(0|([1-9]\d{0,9}))(\.\d{1,2})?$/g;

		return reg.test(editValue);
	}
</script>
</head>
<body onload="init();">
<div style="height:350px;overflow:auto;">
	<ec:ceTable items="meterData" autoIncludeParameters="true"
			var="meterDataItem"
			action="${ctx}/charge_meterDataRegisterAction.do?method=list"
			rowsDisplayed="12"
			width="100%"
			view="pmsview"
			styleClass="gridData"
			>
			<ec:ceRow styleClass="grid"
					  onclick="tableOnclickHandle(this);
					  		   currentId=${meterDataItem.chargeDataId};"
					  onContextMenu="currentRow=this;return ShowContextMenu(event,'quick_rightmenu');">
				<ec:ceColumn property="houseNumber" headerCell="pmsHeadrCell" width="10%" title="${key.charge_meterDataList_houseNumber}" sortable="true"></ec:ceColumn>
				<ec:ceColumn property="owners" headerCell="pmsHeadrCell"  width="10%"  title="${key.charge_meterDataList_ownerName}"></ec:ceColumn>
				<ec:ceColumn property="periodDate" headerCell="pmsHeadrCell"   width="10%" title="${key.charge_meterDataList_period}" sortable="true"></ec:ceColumn>
				<ec:ceColumn property="meterName" headerCell="pmsHeadrCell"   width="10%" title="${key.charge_meterDataList_meterName}"></ec:ceColumn>
				<ec:ceColumn property="thisReading" headerCell="pmsHeadrCell"   width="10%" title="${key.charge_meterDataList_thisReading}" showTitle="false">
	  				<table width="100%" border="0" cellspacing="0" cellpadding="0" id="layer11" class="Price_table_border">
	                    <tr>
	            			<td align="right" class="Price_table_Content_score21">
								<c:choose>
									<c:when test="${meterDataItem.statuz eq '001' || meterDataItem.statuz eq '002'}">
				  						<input name="input" type="text" class="inputNoStyle"
			  						       value="${meterDataItem.thisReading}"
			  						       onMouseOut="if(this.className != 'inputOnClick') this.className='inputNoStyle'"
			  						       onfocus="currentInputValue=this.value;"
			  						       readonly="readonly"
			  						       onBlur="inputSubmit(this);this.fireEvent('onMouseOut');"
			  						       onkeydown="if(event.keyCode == 13)inputSubmit(this) "
			  						       style="text-align:right" size="10">
									</c:when>
									<c:otherwise>${meterDataItem.thisReading}</c:otherwise>
								</c:choose>
			  				</td>
						</tr>
					</table>
				</ec:ceColumn>
				<ec:ceColumn property="lastReading" style="text-align:right;" headerCell="pmsHeadrCell"   width="10%" title="${key.charge_meterDataList_lastReading}"></ec:ceColumn>
				<ec:ceColumn property="wastage" style="text-align:right;" headerCell="pmsHeadrCell"   width="10%" title="${key.charge_meterDataList_dosage}"></ec:ceColumn>
				<ec:ceColumn property="recordTime" headerCell="pmsHeadrCell" cell="date" parse="yyyy-MM-dd" format="yyyy-MM-dd"  width="10%" title="${key.charge_meterDataList_recordDate}"></ec:ceColumn>
				<ec:ceColumn property="statuz" headerCell="pmsHeadrCell"   width="10%" title="状态">
					<c:choose>
						<c:when test="${meterDataItem.statuz eq '001'}">${key.charge_meterDataList_new}</c:when>
						<c:when test="${meterDataItem.statuz eq '002'}">${key.charge_meterDataList_counted}</c:when>
						<c:otherwise>${key.charge_meterDataList_abate}</c:otherwise>
					</c:choose>
				</ec:ceColumn>
			</ec:ceRow>
	</ec:ceTable>
</div>
<div id="quick_rightmenu" style="display:none;" oncontextmenu="return false" class="quick_rightmenu">
	<table width="100%" border="0" cellpadding="1" cellspacing="0" class="grid_quickMenu_bg">
		<tr>
			<td>
			<table width="100%" border="0" cellpadding="2" cellspacing="0">
			<pms:AuthTag authName="charge_meterDataRegisterAction.do?method=initByUser">
			 <tr>
				 <td class="quickMenu_toolbarico">
				 	<a href="#"  onclick="parent.openRecordByUser();" onFocus="this.blur()">
				 		<img src="${ctx}/images/charge_sjlr_ahlr.gif" border="0" align="absbottom" alt=" "/>&nbsp;按户录入
				 	</a>
				 </td>
			  </tr>
			  </pms:AuthTag>
			  <pms:AuthTag authName="menu.nopage.meterEnterData">
	          <tr>
	          <td class="quickMenu_toolbarico">
	          		<a href="#" onMouseOver="show2menu('quick_righ2tmenu',this,event,'quick_rightmenu')" onMouseOut="hidden2menu('quick_righ2tmenu')" onFocus="this.blur()">
	          		<img src="${ctx}/images/charge_sjlr_ablr.gif" alt="" width="16" height="16" border="0" align="absbottom">&nbsp;按表录入&nbsp;&nbsp;&nbsp;&nbsp;
	          		<img src="${ctx}/images/ico_index_start1.gif" border="0" />
	          		</a>
	          	</td>
	          </tr>
	          </pms:AuthTag>
	          <pms:AuthTag authName="charge_meterDataRegisterAction.do?method=editMeterData">
	         <tr>
				<td class="quickMenu_toolbarico">
					<a href="#" onClick="currentMethod='editMeterData';openEdit();" onFocus="this.blur()">
						<img src="${ctx}/images/ico_amend.gif" alt=" "  border="0" align="absbottom" />&nbsp;修 改
					</a>
				</td>
	         </tr>
	         </pms:AuthTag>
	         <pms:AuthTag authName="charge_meterDataRegisterAction.do?method=regulateMeterData">
	         <tr>
          		<td class="quickMenu_toolbarico">
          		   <a href="#" onClick="currentMethod='regulateMeterData';openAdjust();" onFocus="this.blur()">
          			<img src="${ctx}/images/charge_sjlr_tzds.gif" alt=" "  border="0" align="absbottom" />&nbsp;调整读数
          		   </a>
          		</td>
	         </tr>
	         </pms:AuthTag>
	         <pms:AuthTag authName="charge_meterDataRegisterAction.do?method=abateMeterData">
			<tr>
			    <td class="quickMenu_toolbarico">
			    	<a href="#" onClick="parent.openAbateMaterdata();" onFocus="this.blur()">
			    		<img src="${ctx}/images/ico_zuofei.gif" alt=" "  border="0" align="absbottom" />&nbsp;作废
			    	</a>
			    </td>
			</tr>
			</pms:AuthTag>
			</table>
			</td>
		</tr>
	</table>
 <script type="text/javascript">

	var div1=document.getElementById('quick_rightmenu');
	if(div1.getElementsByTagName("tr").length==1){
	div1.innerHTML="";
	}
</script>
</div>
<!--------------------右键二级更多菜单 开始---------------------->
<div id="quick_righ2tmenu" class="quick_menu2" style="display:none;">
  <table width="100%" border="0" cellpadding="1" cellspacing="0" class="grid_quickMenu_bg" onMouseOver="showmy2menu('quick_righ2tmenu')" onMouseOut="hidden2menu('quick_righ2tmenu')">
       <tr>
      <td>
	  <table width="100%" border="0" cellpadding="2" cellspacing="0">
	    <tr>
	         <td class="quickMenu_toolbarico">
	         	<a href="#" onClick="parent.openRecordBySaterMeter();" onFocus="this.blur()">
	         		<img src="${ctx}/images/charge_sjlr_asblr.gif" alt="按水表录入" border="0" align="absbottom"/>&nbsp;按水表录入
	         	</a>
	         </td>
        </tr>
        <tr>
         <td class="quickMenu_toolbarico">
         	<a href="#" onFocus="this.blur()" onClick="parent.openRecordByAmmeter();">
         		<img src="${ctx}/images/charge_sjlr_adblr.gif" alt="按电表录入" border="0" align="absbottom"/>&nbsp;按电表录入
         	</a>
         </td>
        </tr>
      </table>
      </td>
    </tr>
  </table>
</div>
</body>
</html>